package com.ym.user.service.impl;

import com.ym.goods.entity.GoodsClassEntity;
import com.ym.user.dao.UserEntityMapper;
import com.ym.user.entity.UserEntity;
import com.ym.user.feignRpc.goodsRpc.GoodsServerRPC;
import com.ym.user.service.UserService;
import com.ym.utils.exception.CustomException;
//import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserEntityMapper userEntityMapper;
    @Autowired
    private GoodsServerRPC goodsServerRPC;


    @Override
    //@Transactional(readOnly = true)
    //@GlobalTransactional//全局事务控制
    public UserEntity getUserInforById(String userId) throws CustomException {
        GoodsClassEntity goodsClassEntity = new GoodsClassEntity();
        goodsServerRPC.addInfor(goodsClassEntity);
        UserEntity record = new UserEntity();
        record.setId("01");
        record.setPoint(new BigDecimal(99));
        int count = userEntityMapper.updateByPrimaryKeySelective(record);
        if (count == 0) {
            throw new CustomException("修改失败");
        }
        return userEntityMapper.selectByPrimaryKey(userId);
    }
}
